package com.yanggu.bigdata.realtime.utils

import org.wltea.analyzer.core.IKSegmenter

import java.io.StringReader
import scala.collection.mutable.ListBuffer

object KeywordUtil {

  /**
   * 使用ik分词器对字符串进行分词
   * @param keyword
   */
  def analyze(keyword: String) = {
    val reader = new StringReader(keyword)
    val segmenter = new IKSegmenter(reader, true)
    val buffer = ListBuffer[String]()
    var lexeme = segmenter.next()
    while (lexeme != null) {
      val text = lexeme.getLexemeText
      buffer.append(text)
      lexeme = segmenter.next()
    }
    buffer
  }

  def main(args: Array[String]): Unit = {
    val keyword = "Apple iPhoneXSMax (A2104) 256GB 深空灰色 移动联通电信 4G 手机双卡双待"
    println(analyze(keyword))
  }

}
